
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome()

driver.get('https://www.baidu.com/')

# 通过ID定位
# driver.find_element_by_id('kw').send_keys('python')
# driver.find_element(By.ID, 'kw').send_keys('python')

# 通过class_name
# driver.find_element_by_class_name('s_ipt').send_keys('python')
# driver.find_element(By.CLASS_NAME, 's_ipt').send_keys('python')

# 通过name属性
# driver.find_element_by_name('wd').send_keys('居然')
# driver.find_element(By.NAME, 'wd').send_keys('python')

# 通过标签名字
# head = driver.find_element_by_tag_name('head')
# 获取页面所有的input标签
inputTag = driver.find_elements_by_tag_name('input')
# 获取页面源代码
print(driver.page_source)
# print(type(head))
# print(inputTag)
# print(len(inputTag))

# 通过xpath
# driver.find_element_by_xpath('//input[@id="kw"]').send_keys('java')

# 通过css选择器  . class  # id
# driver.find_element_by_css_selector('.s_ipt').send_keys('python')

time.sleep(2)

# driver.close()

